<?php
namespace YunCangChu\Controller;
use Think\Controller;
class WeixinController extends Controller
{
    public function get()
    {
        header('Content-type: application/json');
		$price = (string)I('price')*100;
        require_once "/weixin/lib/WxPay.Api.php";
        require_once "/weixin/example/WxPay.JsApiPay.php";
        require_once "/weixin/example/WxPay.Config.php";
        require_once '/weixin/example/log.php';
        try{
            $tools = new \JsApiPay();
            $input = new \WxPayUnifiedOrder();
            $input->SetBody("test");
            $input->SetAttach("test");
            $input->SetOut_trade_no(I('order'));
            $input->SetTotal_fee($price);
            $input->SetTime_start(date("YmdHis"));
            $input->SetTime_expire(date("YmdHis", time() + 600));
            $input->SetGoods_tag("test");
            $input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php");
            $input->SetTrade_type("JSAPI");
            $input->SetOpenid(Cookie("openId"));
            $config = new \WxPayConfig();
            $order = \WxPayApi::unifiedOrder($config, $input);
            $jsApiParameters = $tools->GetJsApiParameters($order);
            echo $jsApiParameters;
        } catch(Exception $e) {
            print_r($e);die;
            Log::ERROR(json_encode($e));
        }
    }
}